<div class="row">
    <div class="col-xs-12">
        <div class="panel">
            <div class="btn-group">
                <button class="btn btn-primary" type="button"><span class="fa fa-plus-square" aria-hidden="true">&nbsp;</span>添加文档</button>
                <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle" type="button" aria-expanded="false">
                    <span class="caret"></span>
                    <span class="sr-only">请选择文档类型</span>
                </button>
                <ul role="menu" class="dropdown-menu">
                    <li><a href="/admin/manage/content/add/content">普通文档</a></li>
                    <li><a href="/admin/manage/content/add/plug">Jquery插件</a></li>
                    <!--<li><a href="/admin/manage/content/add/film">影片文档</a></li>-->
                </ul>
            </div>
        </div>
        <div class="box">
            <div class="box-header">
                <h3 class="box-title"></h3>
                <div class="box-tools">
                    <form action="/admin/manage/contentList" name="searchForm" >
                        <div class="input-group">
                            <input type="text" name="searchKey" id="searchInput" class="form-control input-sm pull-right" style="width: 200px;" placeholder="请输入关键字" value="<%= searchKey%>"/>
                            <div class="input-group-btn">
                                <button class="btn btn-sm btn-default" type="submit"><i class="fa fa-search"></i></button>
                            </div>
                        </div>
                    </form>
                </div>
            </div><!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
                <table class="table table-hover">
                    <tr>
                        <th>选择</th>
                        <th>文章标题</th>
                        <th>创建时间</th>
                        <th>类目</th>
                        <th>来源</th>
                        <th>类型</th>
                        <th>推荐</th>
                        <th>点击</th>
                        <th>权限</th>
                        <th>发布人</th>
                        <th>操作</th>
                    </tr>
                    <tr ng-repeat="content in data">
                        <td><input type="checkbox" class="mini"/></td>
                        <td>{{content.title}}</td>
                        <td>{{content.date | date : "M/d/yy h:mm a"}}</td>
                        <td>{{content.category}}</td>
                        <td>{{content.from}}</td>
                        <td>{{content.type}}</td>
                        <td ng-class="{true:'text-danger'}[content.isTop==1]"><i class="fa fa-fw fa-flag"></i></td>
                        <td>{{content.clickNum}}</td>
                        <td><span class="label label-success">{{content.state}}</span></td>
                        <td>{{content.author}}</td>
                        <td>
                            <a href="/admin/manage/content/edit/{{content.type}}/{{content._id}}" role="button"  title="编辑" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a>
                            <a href="###" role="button"  title="推荐" ng-click="topContent(content._id,1)" class="btn btn-warning btn-xs" ng-show="content.isTop == 0"><i class="fa fa-thumbs-o-up"></i></a>
                            <a href="###" role="button"  title="取消推荐" ng-click="topContent(content._id,0)" class="btn btn-default btn-xs" ng-show="content.isTop == 1"><i class="fa fa-thumbs-o-down"></i></a>
                            <!--<button class="btn btn-primary btn-xs" type="button" title="编辑"><i class="fa fa-edit"></i></button>-->
                            <button class="btn btn-default btn-xs" type="button" title="删除" data-whatever="{{content._id}}" data-toggle="modal" data-target="#checkIfDel"><i class="fa fa-trash-o"></i></button>
                        </td>
                    </tr>
                </table>
            </div><!-- /.box-body -->
            <div class="box-footer">
                <!--分页-->
                <div class="row">
                    <div class="col-xs-6">
                        <div class="dataTables_info" id="example2_info">显示 {{startNum}} 到 {{startNum + limit -1}} 条，共 {{totalItems}} 条记录</div>
                    </div>
                    <div class="col-xs-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <ul class="pagination">
                                <li ng-class="{true:'disabled'}[currentPage==1]"><a href="javascript:void(0);" ng-click="prevPage()">← 上一页</a></li>
                                <li ng-repeat="page in pages" ng-class="{true:'active'}[currentPage==page]"><a href="javascript:void(0);" ng-click="loadPage(page)">{{ page }}</a></li>
                                <li ng-class="{true:'disabled'}[currentPage==totalPage]"><a href="javascript:void(0);" ng-click="nextPage()">下一页 → </a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div><!-- /.box -->
    </div>


    <!--信息提示模态窗口-->
    <div class="modal fade" id="checkIfDel">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">系统提示</h4>
                </div>
                <div class="modal-body">
                    <h4><i class="icon fa fa-warning"></i> 确认删除该条记录？</h4>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" ng-click="delContent()">删除</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal">取消</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

</div>

<script>
    angular.module("adminApp",[])
            .controller("adminCtrl",function($scope,$http){
                $scope.formData = {};

                //获取管理员列表信息
                getData($scope,$http,$("#searchInput").val());
                //删除用户
                $('#checkIfDel').on('show.bs.modal', function (event) {
                    var obj = $(event.relatedTarget);
                    $scope.targetID = obj.data('whatever');
                }).on('hide.bs.modal', function (event) {
                    $scope.targetID ="";
                });
                //确认执行删除
                $scope.delContent = function () {
                    var currentID =  $scope.targetID;
                    $http.get("/admin/manage/ContentList/del?uid="+currentID).success(function(result){
                        $('#checkIfDel').modal("hide");
                        console.log("del success!");
                        getData($scope,$http,$("#searchInput").val());
                    })
                };

//                文章推荐
                $scope.topContent = function(id,m){

                    $http.get("/admin/manage/ContentList/topContent?uid="+id+"&isTop="+m).success(function(result){
                        getData($scope,$http,$("#searchInput").val());
                    })

                };

//                文章搜索
//                $scope.subSearch = function(){
//                    alert("--clickalert---"+$scope.keywords)
//                    getPageInfos($scope,$http,"/admin/manage/contentList/listByParam")
//                }

//
            });

    function getData($scope,$http,keywords){
        $scope.currentPage = 1;
        $scope.totalPage = 1;
        $scope.totalItems = 1
        $scope.limit = 10;
        $scope.pages = [];
        $scope.startNum = 1;
        $scope.keywords = keywords;
        getPageInfos($scope,$http,"/admin/manage/contentList/listByParam");
    }

</script>